<template>
    <div id="Novel_Details">
        <el-row :gutter="20">
            <el-col :span="this.$store.state.elColNum">
                <el-form ref="form" :model="form" :label-width="this.$store.state.labelWidth" size="small">
                    <!--                    <el-form-item label="排序权值">-->
                    <!--                        <el-input v-model="form.list_order"></el-input>-->
                    <!--                    </el-form-item>-->
                    <el-form-item label="小说标题">
                        <el-input v-model="form.title"></el-input>
                    </el-form-item>
                    <el-form-item label="小说作者">
                        <el-input v-model="form.author"></el-input>
                    </el-form-item>
                    <el-form-item label="小说封面图链接">
                        <img v-if="form.coverpic" :src="form.coverpic" class="avatar">
                    </el-form-item>
                    <el-form-item label="描述">
                        <el-input v-model="form.desc"></el-input>
                    </el-form-item>

                    <!--                    <el-form-item label="发布栏目">-->
                    <!--                        <el-cascader-->
                    <!--                                v-model="areaIds"-->
                    <!--                                :options="areaList"-->
                    <!--                                :props="props"-->
                    <!--                                clearable-->
                    <!--                                style="width: 100%">-->
                    <!--                        </el-cascader>-->

                    <!--                    </el-form-item>-->
                    <el-form-item label="小说分类">
                        <el-checkbox-group v-model="form.cateids">
                            <el-checkbox :label="key" v-for="(value,key,index) in classList" :key="index">{{value}}
                            </el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <!--                    <el-form-item label="小说状态">-->
                    <!--                        <el-select v-model="form.iswz" placeholder="请选择">-->
                    <!--                            <el-option label="连载中" value="1"></el-option>-->
                    <!--                            <el-option label="已完结" value="2"></el-option>-->
                    <!--                        </el-select>-->
                    <!--                    </el-form-item>-->
                    <!--                    <el-form-item label="新书/非新书">-->
                    <!--                        <el-select v-model="form.isnew" placeholder="请选择">-->
                    <!--                            <el-option label="新书" value="1"></el-option>-->
                    <!--                            <el-option label="非新书" value="2"></el-option>-->
                    <!--                        </el-select>-->
                    <!--                    </el-form-item>-->
                    <!--                    <el-form-item label="长篇/短篇">-->
                    <!--                        <el-select v-model="form.islong" placeholder="请选择">-->
                    <!--                            <el-option label="长篇" value="1"></el-option>-->
                    <!--                            <el-option label="短篇" value="2"></el-option>-->
                    <!--                        </el-select>-->
                    <!--                    </el-form-item>-->
                    <el-form-item label="男频/女频">
                        <el-select v-model="form.issex" placeholder="请选择">
                            <el-option label="男频" value="1"></el-option>
                            <el-option label="女频" value="2"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
        <div style="display: flex;justify-content: flex-end">
            <el-button type="success" plain size="small" @click="pass()">通过</el-button>
            <el-button type="danger" plain size="small" @click="refuse()">拒绝</el-button>
        </div>
    </div>
</template>

<script>
  import {uploadimg, isRealNum} from "../../utils/common";
  import quillConfig from '../../utils/quill-config.js'

  export default {
    name: "system_site",
    props: ['bookId'],
    data() {
      return {
        props: {multiple: true},
        form: {
          title: '',
          author: '',
          infopic: '',
          coverpic: '',
          selectpic: '',
          cateids: [],
          isfw: '',
          isnew: '',
          islong: '',
          issex: '',
          tag: '',
          iswz: '',
          isbg: '',
          remark: '',
          list_order: '',
          desc: '',
          paychapter: '',
          thermal: '',
          hots: '',
          likes: '',
          sharetitle: '',
          sharedesc: '',
          tchapter: '',
          coin: '',
          isrecommend: '',
          ishow: '',
          status: '',
          columnids: []
        },
        editorOption: quillConfig,
        areaList: [],
        classList: [],
        areaIds: [],
        id: '',
      }
    },
    created() {
      this.getCateIds();
      // this.getAreas();
      this.id = this.bookId;
      if (this.id) {
        this.$axios.get('admin/novel/' + this.id, {}).then((res) => {
          let data = res.data;
          for (let key in data) {
            if (isRealNum(data[key])) {
              data[key] = data[key].toString()
            }
          }
          data.cateids = data.cateids.split(',');
          let newInfo = [];
          if (data.column_info.length > 0) {
            data.column_info.map((num) => {
              newInfo.push([num.channel_id, num.column_id])
            });
          }
          this.form = data;
          this.areaIds = newInfo;
          this.$forceUpdate()
        })
      }
    },
    methods: {
      getCateIds() {
        this.$axios.post("admin/novel/category", '').then((res) => {
          this.classList = res.data;
        });
      },
      getAreas() {
        this.$axios.post("admin/channel/getAll", '').then((res) => {
          let data = res.data;
          data.map(async (num) => {
            num.value = num.id;
            num.label = num.title;
            num.children.map((item) => {
              item.value = item.id;
              item.label = item.title;
            })
          });
          this.areaList = data;
        });
      },
      closeDetails() {
        this.$emit("closeDatails", false)
      },
      pass() {
        let status = 1;
        this.communal(this.id, status)
      },
      refuse() {
        let status = 2;
        this.communal(this.id, status)
      },
      communal(id, status) {
        this.$confirm('确定要进行操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post('admin/writer/anime_review', {id: id, status: status}).then((res) => {
            this.$message.success('操作成功!');
            this.closeDetails();
          });
        })
      },
    }
  }
</script>

<style scoped lang="scss">

</style>